<?php
$seitcm_student_id = isset($_GET['id']) ? $_GET['id'] : 0;
$seitcm_student_info = seitcm_get_single_student($seitcm_student_id);
?>
<?php
	$seitcm_formvalidatemess = '';
	$seitcm_formvalidate = true;
	$seitcm_added = true;
	$seitcm_callback = false;
	if(isset($_POST['seitcm_class_register_submit_new']))
	{
		$seitcm_callback = true;
	}
	$seitcm_register_class = isset($_POST['seitcm_register_class']) ? $_POST['seitcm_register_class'] : '0';
	$seitcm_register_discount = isset($_POST['seitcm_register_discount']) ? $_POST['seitcm_register_discount'] : '0';
	$seitcm_register_note = isset($_POST['seitcm_register_note']) ? $_POST['seitcm_register_note'] : '';
	$seitcm_register_collect_fee = isset($_POST['seitcm_register_collect_fee']) ? 1 : 0;
	if($seitcm_callback)
	{
		if($seitcm_register_class=='0')
		{
			$seitcm_formvalidate = false;
			$seitcm_formvalidatemess = $seitcm_formvalidatemess.__('"Class" has not selected','SEITCM').'<br />';
		}
		if(seitcm_check_student_registed_class($seitcm_student_id, $seitcm_register_class))
		{
			$seitcm_formvalidate = false;
			$seitcm_formvalidatemess = $seitcm_formvalidatemess.__('Student has registed to this class before','SEITCM').'<br />';
		}	
	}
	if($seitcm_callback && $seitcm_formvalidate)
	{
		$seitcm_register_time = seitcm_get_current_sql_datetime();
		if(seitcm_register_class($seitcm_student_id, $seitcm_register_class, $seitcm_register_discount, $seitcm_register_collect_fee,$seitcm_register_time , $seitcm_register_note))
		{
			$seitcm_added = true;
			?>
			<!-- html -->
			<div id="seitcm_wrapper_ms">
			    <div id="seitcm_header">
			        <div id="seitcm_head_logo">
			            <h1><?php _e('Sunshine Education','SEITCM') ?></h1>
			            <h2><?php _e('Registing class for ' . $seitcm_student_info->display_name,'SEITCM'); ?></h2>
			        </div>
			        
			        <div id="seitcm_head_menu">
			            <a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=list"><?php _e('Class list','SEITCM')?></a>
			            <a class="seitcm_button" href="admin.php?page=seitcm_students_option_menu&module=list"><?php _e('Student list','SEITCM')?></a>
			        </div>
			        <div class="seitcm_clearfload"></div>
			    </div>
			    <div class="seitcm_bigwidget_block">
			        <div class="seitcm_bigwidget_block_inner">
			            <div class="ui-widget seitcm_messbox">
			                <div class="ui-state-highlight ui-corner-all" style="padding: 0 .7em;">
			                    <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
			                    <strong><?php _e('Success! ','SEITCM')?></strong><?php _e('Student has subscribe to class','SEITCM')?></p>
			        		</div>
			        	</div>
			        </div>
			    </div>
			</div>
			<!-- html -->
			<?php 
		}
		else
		{
			$seitcm_added = false;
		}
	}
	else {
		$seitcm_class_list = seitcm_get_list_class_for_reg();
?>
<div id="seitcm_wrapper_ms">
	<div id="seitcm_header">
    	<div id="seitcm_head_logo">
            <h1><?php _e('Sunshine Education','SEITCM') ?></h1>
            <h2><?php _e('Registing class for ' . $seitcm_student_info->display_name,'SEITCM'); ?></h2>
		</div>
        
        <div id="seitcm_head_menu">
        	<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=list"><?php _e('Class list','SEITCM')?></a>
        	<a class="seitcm_button" href="admin.php?page=seitcm_students_option_menu&module=list"><?php _e('Student list','SEITCM')?></a>
        </div>
        <div class="seitcm_clearfload"></div>
    </div>
    <div class="seitcm_bigwidget_block">
    	<div class="seitcm_bigwidget_block_inner">
    		<?php 
	            if($seitcm_callback && !$seitcm_formvalidate)
				{
				?>
	            <div class="ui-widget seitcm_messbox">
					<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
						<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
						<strong><?php _e('Error!','SEITCM')?><br /></strong><?php echo $seitcm_formvalidatemess?></p>
					</div>
				</div>
				<?php
				}
				elseif(!$seitcm_added)
				{
				?>
				<div class="ui-widget seitcm_messbox">
					<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
						<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
						<strong><?php _e('Bug deteted!','SEITCM')?></strong><br /><?php _e('Input\'s corect but us system had some error now. try again later','SEITCM')?></p>
					</div>
				</div>
				<?php
				}
				?>
    		<form class="seitcm_form seitcm_class_form_new" action="" method="post">
                <fieldset>
                    <label for="seitcm_register_class"><?php _e('Class','SEITCM')?></label>
                    <select id="seitcm_register_class" name="seitcm_register_class" class="seitcm_combobox">
                    	<option value="0" <?php if ($seitcm_register_class == '0') echo ' selected="selected"'; ?>><?php _e('Chose class ...','SEITCM')?></option>
					    <?php 
					    foreach ($seitcm_class_list as $seitcm_class)
					    {
					    	?>
					    	<option value="<?php echo $seitcm_class->id?>" <?php if ($seitcm_register_class == $seitcm_class->id) echo ' selected="selected"'; ?>><?php echo $seitcm_class->codename. ' - ' . $seitcm_class->classcode . '('. seitcm_get_learn_time_string($seitcm_class->learntime) .')'?></option>
					    	<?php 
					    }
					    ?>
					</select>
					
					<label for="seitcm_register_discount"><?php _e('Discount','SEITCM')?></label>
                    <input type="text" name="seitcm_register_discount" id="seitcm_register_discount" style="width: 78px"
                    	value="<?php echo $seitcm_register_discount?>" class="text ui-widget-content ui-corner-all seitcm_numberic_texbox" />
                    <span class="seitcm_extent_input">%</span>
					<a class="seitcm_button seitcm_extent_input seitcm_call_discount_input"><?php _e('Discount Code','SEITCM')?></a>
					<div title="<?php _e('Discount code [not available, comming soon]','SEITCM')?>" style="display: none; text-align: center;" class="seitcm_discount_input_dialog">
						<span style="margin: 8px 0px; display: block">
						<label for="seitcm_discount_code"><?php _e('Discount Code  ','SEITCM')?></label>
						<input type="text" name="seitcm_discount_code" id="seitcm_discount_code"
	                    	value="" class="text ui-widget-content ui-corner-all" />
	                    <input type="button" class="seitcm_button seitcm_scan_discount_code" value="OK">
	                    </span>
					</div>
					<script type="text/javascript">
					  $(function() {
					    $( ".seitcm_discount_input_dialog" ).dialog({
					      autoOpen: false,
				          height: 100,
				          width: 350,
				          modal: true,
					      show: {
					        effect: "blind",
					        duration: 500
					      },
					      hide: {
					        effect: "fadeOut",
					        duration: 200
					      }
					    });
					 
					    $( ".seitcm_call_discount_input" ).click(function() {
					      $( ".seitcm_discount_input_dialog" ).dialog( "open" );
					    });

					    $( ".seitcm_scan_discount_code" ).click(function() {
						    if(1){
							    $( 'input[name="seitcm_register_discount"]' ).val('0');
					    		$( ".seitcm_discount_input_dialog" ).dialog( "close" );
						    }
					    });
					  });
					  </script>
					
                    <label for="seitcm_class_note"><?php _e('Note','SEITCM')?></label>
                    <div class="seitcm_form_editer_wrapper">
                    <?php
						$settings = array(
							'textarea_name' => 'seitcm_class_note',
							'media_buttons' => true,
							'editor_height' => '350px',
							'tinymce' => array(
								'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
									'bullist,blockquote,|,justifyleft,justifycenter' .
									',justifyright,justifyfull,|,link,unlink,|' .
									',spellchecker,wp_fullscreen,wp_adv'
							)
						);
						wp_editor( $seitcm_register_note, 'seitcm_register_note', $settings );
					?> 
                    </div>
                    
                    <label for="submit" ></label>
                    <span>
                        <input style="width: 12px; clear: none;" type="checkbox" <?php echo $seitcm_register_collect_fee ? 'checked="checked"' : ''?> value="colectfee" name="seitcm_register_collect_fee" id="seitcm_register_collect_fee"/>
                        <label style="width: 200px; clear: right; float: left; margin-top: 0px;" for="seitcm_register_collect_fee"><?php _e('Collet fee')?></label>
                    </span>
                    <label for="submit" ></label>
                    <span class="seitcm_button_wrapper">
                        <input type="submit" value="<?php _e('Create','SEITCM')?>" name="seitcm_class_register_submit_new" id="seitcm_class_register_submit_new"/>
                        <input type="reset" value="<?php _e('Reset','SEITCM')?>" name="seitcm_class_register_reset_new" id="seitcm_class_register_reset_new"/>
                    </span>
                </fieldset>
            </form>
            <div class="seitcm_clearfload"></div>
    	
    	</div>
	</div>
</div>
<?php 
	}
?>